package com.example.text.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.text.R;
import com.example.text.mode_list;

import java.lang.annotation.ElementType;
import java.util.List;

public class List_viewAdapter extends BaseAdapter {

   private List<mode_list> lists;
   private Context context;

    public List_viewAdapter(List<mode_list> lists, Context context) {
        this.lists = lists;
        this.context = context;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int i) {
        return lists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null)
        {
            view= LayoutInflater.from(context).inflate(R.layout.mode_list, viewGroup, false);
            holder=new ViewHolder();
            holder.img = view.findViewById(R.id.img);
            holder.title =view.findViewById(R.id.title);
            holder.content=view.findViewById(R.id.content);
            //让v和ViewHolder绑定在一起
            view.setTag(holder);
            Log.d("xx","1");
        }else
        {
            holder = (ViewHolder) view.getTag();
        }

        holder.title.setText(lists.get(i).getTitle());
        holder.img.setImageResource(lists.get(i).getImg());
        holder.content.setText(lists.get(i).getContent());

        return view;
    }
    class ViewHolder{
        ImageView img;
        TextView title;
        TextView content;
    }
}
